/************************* (C) COPYRIGHT 2008 Domain **************************
 * File Name   : config.h                                                     *
 * Author      : Domain                                                       *
 * E-mail      : do.main@msn.com                                              *
 * Version     : 1.0                                                          *
 * Date        : 2008/5/27                                                    *
 * Description :                                                              *
 ******************************************************************************/

/* Global Definitions ---------------------------------------------------------*/
#ifndef NULL
  #define NULL                  ((void *)0)
#endif

#define APP_VER			            0x00020001           /* Application Version */
#define MAJOR_VER(x)	          (((x) & 0xFFFF0000) >> 16)   /* Major version, not compatible */
#define MINOR_VER(x)	          ((x) & 0x0000FFFF)   /* Minor version, downward compatible */

#define DEFAULT_ID              "\x012\x034\x056"

#define FEEDBACK_MSG            "@K566B@J"
#define DEBUG_MSG               "@K666C@J"
#define LOWPOWER_MSG            "@K676D@J"
#define BACKUP_MSG              "@K686E@J"

#define RESET_TIME              2000
#define MAX_WAIT_TIME           60*1000

#define FLAG_FULL               0x00000001       /* Buffer Full Flag       */
#define FLAG_STOP               0x00000002       /* GSM Stop Flag          */
#define FLAG_ALARM              0x00000004       /* RTC Alarm Flag         */
#define FLAG_OVERFLOW           0x00000008       /* Buffer Overflow Flag   */
#define FLAG_GPRS               0x00000010       /* GPRS Connected Flag    */
#define FLAG_POWER              0x00000020       /* Power Saving Flag      */
#define FLAG_CONNECTED          0x00000040       /* Network Connected Flag */
#define FLAG_FLASH              0x00000080       /* LED Flash Flag         */
#define FLAG_POWERDOWN          0x00000100       /* Start Power Down Flag  */
#define FLAG_CMUX               0x00000200       /* CMUX Flag              */

/*           Reserved Bits             */
/* 31----24 23----16 15-----8 7------0 */
/* |------| |------| |------| |------| */
/* 00000000 00000000 00000000 00000000 */
/* |<------------------------>||<-->|| */
/*              3                 2  1 */
/*                                     */
/* Bit0:       Feedback Flag           */
/* Bit1-Bit6:  Signal                  */
/* Bit7-Bit31: Unused                  */
#define FLAG_FEEDBACK           0x00000001
#define FLAG_SIGNAL             0x0000007E

#define SHIFT_FEEDBACK          0
#define SHIFT_SIGNAL            1

/* GPIO Configuration ---------------------------------------------------------*/
#define GPIO_USART1_RX          GPIOA
#define GPIO_PIN_USART1_RX      GPIO_Pin_10
#define GPIO_USART1_TX          GPIOA
#define GPIO_PIN_USART1_TX      GPIO_Pin_9
#define GPIO_USART1_CTS         GPIOA
#define GPIO_PIN_USART1_CTS     GPIO_Pin_11
#define GPIO_USART1_RTS         GPIOA
#define GPIO_PIN_USART1_RTS     GPIO_Pin_12

#define GPIO_USART2_RX          GPIOA
#define GPIO_PIN_USART2_RX      GPIO_Pin_3
#define GPIO_USART2_TX          GPIOA
#define GPIO_PIN_USART2_TX      GPIO_Pin_2
#define GPIO_USART2_CTS         GPIOA
#define GPIO_PIN_USART2_CTS     GPIO_Pin_0
#define GPIO_USART2_RTS         GPIOA
#define GPIO_PIN_USART2_RTS     GPIO_Pin_1

#define GPIO_USART3_RX          GPIOB
#define GPIO_PIN_USART3_RX      GPIO_Pin_11
#define GPIO_USART3_TX          GPIOB
#define GPIO_PIN_USART3_TX      GPIO_Pin_10
#define GPIO_USART3_CTS         GPIOB
#define GPIO_PIN_USART3_CTS     GPIO_Pin_13
#define GPIO_USART3_RTS         GPIOB
#define GPIO_PIN_USART3_RTS     GPIO_Pin_14

#define GPIO_RING0              GPIOB
#define GPIO_PIN_RING0          GPIO_Pin_12

#define GPIO_DTR0               GPIOA
#define GPIO_PIN_DTR0           GPIO_Pin_11

#define GPIO_EMERGOFF           GPIOA
#define GPIO_PIN_EMERGOFF       GPIO_Pin_7

#define GPIO_IGT                GPIOB
#define GPIO_PIN_IGT            GPIO_Pin_0

#define GPIO_LEDCTL             GPIOA
#define GPIO_PIN_LEDCTL         GPIO_Pin_6
#define GPIO_LEDSTL1            GPIOA
#define GPIO_PIN_LEDSTL1        GPIO_Pin_5
#define GPIO_LEDSTL2            GPIOA
#define GPIO_PIN_LEDSTL2        GPIO_Pin_4

#define GPIO_KEY				GPIOB
#define GPIO_PIN_KEY            GPIO_Pin_6
#define GPIO_PIN_KEY2           GPIO_Pin_7
#define GPIO_PIN_KEY1           GPIO_Pin_8

#define GPIO_ENGPRSPOWER		GPIOB
#define GPIO_PIN_ENGPRSPOWER    GPIO_Pin_9

#define GPIO_ENLCDPOWER			GPIOB
#define GPIO_PIN_ENLCDPOWER    	GPIO_Pin_15

/* GPRS Configuration ---------------------------------------------------------*/
#define PPPAUTHTYPE             PPPAUTHTYPE_PAP

#define LINK_A                  0x55
#define LINK_B                  0x33

#define MAX_TRY_TIMES           3

/* SMS Configuration ----------------------------------------------------------*/
#define SMS_PDU                 1
#define SMS_UNICODE             0
#define SMS_MAX_TRY             3
#define SMS_TIMEOUT             3*60*1000

/* Modem Configuration --------------------------------------------------------*/
#define ACTIVE_MODEM_TIMES      3
#define DIAL_GPRS_TIMES         3
#define ACTIVE_SLEEP_TIME       5000

/* USART Configuration --------------------------------------------------------*/
#define USE_USART1              1
#define USE_USART2              1
#define USE_USART3              1
    
	           
#define USART_SENSOR            USART1
#define USART_MODEM             USART3
#define USART_DEBUG             USART1
//#define USART_DEBUG             USART2		   //for test by lee
#define USART_SERVER            USART_SENSOR
//#define USART_SERVER            USART2			//for test by lee

#define F_SENSOR                (FILE*)USART_SENSOR
#define F_MODEM                 (FILE*)USART_MODEM
#define F_DEBUG                 (FILE*)USART_DEBUG

#define ALL_CHANNEL             -1
#define GPRS_CHANNEL            1
#define SMS_CHANNEL             2
#define VOICE_CHANNEL           3    

#ifdef USE_STM3210B_EVAL
  #define BUF_SENSOR_SIZE       /*2048*/1536
  #define BUF_MODEM_SIZE        /*2048*/2560
  #define BUF_MSG_SIZE          50
  #define BUFFER_SIZE           1422
  #define MAX_SMS_FRAGMENT      2
  #define MAX_LONG_SMS          1
  #undef READ_ALL_SMS
  #ifdef READ_ALL_SMS
    #define BUF_SMS_SIZE        1024
  #else
    #define BUF_SMS_SIZE        sizeof(SendMsgType)+50
  #endif
#else
  #define BUF_SENSOR_SIZE       3584/*5120*/
 // #define BUF_MODEM_SIZE        30720/*20480*/
 //  #define BUF_MODEM_SIZE       30000//first change,ok
   #define BUF_MODEM_SIZE       29920 
  #define BUF_MSG_SIZE          150
  #define BUFFER_SIZE           1422
  #define MAX_SMS_FRAGMENT      3
  #define MAX_LONG_SMS          3
  #define BUF_SMS_SIZE          5120/*10240*/
#endif

#define SENSOR_BAUDRATE         9600
#define MODEM_BAUDRATE          115200

/* SysTick Configuration ------------------------------------------------------*/
#define SYSTICK_BASE            9000  /* 9000 / 9MHz = 1ms */
#define SYSTICK_TIMES           50	  /* Trigger every 50ms */
#define SYSTICK_COUNTER         SYSTICK_BASE * SYSTICK_TIMES   

/* RTC Configuration ----------------------------------------------------------*/
#define RTC_COUNTER             0
#define RTC_ALARM               20

extern unsigned long            GlobalFlag;

#define SetFlag(g, f)           (g) |= (f)
#define ResetFlag(g, f)         (g) &= ~(f)
#define CheckFlag(g, f)         ((g) & (f))
#define SetFlagValue(g,f,v,s)   (g) = (((g) & ~(f)) | ((v) << (s)))
#define GetFlagValue(g,f,s)     (((g) & (f)) >> (s))

#define SINC(v, s)              do {             \
                                  ++(v);         \
                                  if ((v) > (s)) \
                                    (v) -= (s);  \
                                } while(0)

#define SDEC(v, s)              do {             \
                                  --(v);         \
                                  if ((v) < 0)   \
                                    (v) += (s);  \
                                } while(0)

#define SLENGTH(i, o, s, v)     do {               \
                                  (v) = (i) - (o); \
                                  if ((v) < 0)     \
                                    (v) += (s);    \
                                } while(0)

/************************* (C) COPYRIGHT 2008 Domain ******* END OF FILE ******/
